/**
' This is a part of the Primavera Portfiolio Management API examples.
' Copyright 1998, 2020, Oracle and/or its affiliates. All Rights Reserved.
'
' This source code is only intended as a supplement to the
'   Primavera Portfolio Management Enterprise API
' electronic documentation provided with the product.
'
' This source code is compatible with Primavera Portfolio Management 20.0 
**/

//*************************************************
// Get list of values in 'Domains' value list
//*************************************************

using System;
using System.Windows.Forms;

namespace ProSightWSExamples
{
        public class CpsPortfoliosValueList_GetValues_Example_1
        {
                private System.Net.CookieContainer mCookies = null;

                // Login needs to be called only once per session
                public void Login(string actualServerName) 
                {
                        try 
                        {
                                // mCookies is of type System.Net.CookieContainer
                                if (mCookies == null) 
                                        mCookies = new System.Net.CookieContainer();

                                // psPortfoliosSecurityRef is obtained by adding a web reference to
                                // http://refservername/ProSightWS/psPortfoliosSecurity.asmx?wsdl
                                psPortfoliosSecurityRef.psPortfoliosSecurity psSecurity = 
                                        new psPortfoliosSecurityRef.psPortfoliosSecurity();
                                        
                                psSecurity.Url = "http://" + actualServerName + "//ProSightWS/psPortfoliosSecurity.asmx?wsdl";
                                
                                psSecurity.CookieContainer = mCookies;
                                psSecurity.Login("admin", "Password", 10000); // Never code the password in the source file
                        }
                        catch (System.Web.Services.Protocols.SoapException E) 
                        {
                                // in case of exception, print the error info
                                MessageBox.Show("Error: " + 
                                        E.Detail.InnerText +  // This is the integer code of the error
                                        " " + E.Message, 
                                        "Login");
                                // in a real system, the Message is only displayed to support personnel, 
                                // not to the user
                        }
                        catch (System.Exception E) 
                        {
                                MessageBox.Show("Unexcpected Error: \n" + 
                                        E.ToString(), 
                                        "Login");
                        }           
                }               

                public void psPortfoliosValueList_GetValues_Example_1(string actualServerName) 
                {
                        try 
                        {
                                // psPortfoliosValueListRef is obtained by adding a web reference to
                                // http://servername/ProSightWS/psPortfoliosValueList.asmx?wsdl 
                                psPortfoliosValueListRef.psPortfoliosValueList ValueListObj =
                                        new psPortfoliosValueListRef.psPortfoliosValueList();
                                
                                ValueListObj.Url = "http://" + actualServerName + "//ProSightWS/psPortfoliosValueList.asmx?wsdl";
                                
                                // Associate ValueListObj with the session so that it inherits the login credentials
                                ValueListObj.CookieContainer = mCookies;


                                psPortfoliosValueListRef.psPortfoliosValueListValueInfo[] retVal = ValueListObj.GetValues(
                                        @"Domains"  // sName             
                                        );
                         

                                string msg = "Total of " + retVal.Length + " results:\n";
                        
                                #region Analyze result                  
                        
                                int i=0;
                                foreach(psPortfoliosValueListRef.psPortfoliosValueListValueInfo infoObj in retVal) 
                                {
                                        int ID = infoObj.ID;
                                        string Text = infoObj.Text;
                                        float Weight = infoObj.Weight;
										double WeightDouble = infoObj.WeightDouble;

                                        msg += (i++) + ": ";
                                        msg += "ID=" + ID + ", ";
                                        msg += "Text=" + Text + ", ";
										msg += "Weight=" + Weight + ", ";
                                        msg += "WeightDouble=" + WeightDouble + "\n";
                                }       
                                #endregion Analyze result
                                                 
                                MessageBox.Show(msg, @"Get list of values in 'Domains' value list");


                        }
                        catch (System.Web.Services.Protocols.SoapException E)
                        {
                                MessageBox.Show("Error: " + 
                                                E.Detail.InnerText +  // This is the integer code of the error
                                                " " + E.Message, 
                                                @"Get list of values in 'Domains' value list");
                                                // in a real system, the Message is only displayed to support personnel, 
                                                // not to the user
                        }
                        catch (System.Exception E) 
                        {
                                MessageBox.Show("Unexcpected Error: \n" + 
                                                E.ToString(),
                                                @"Get list of values in 'Domains' value list");
                        }
                }                 
        }
}

    

